package com.eample.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import com.eample.pages.MyPageFactory;

public class LoginPage extends AnyPage {

	@FindBy(id = "loginform")
	public WebElement loginForm;

	@FindBy(id = "username")
	public WebElement userNameField;

	@FindBy(name = "password")
	public WebElement passwordField;

	@FindBy(name = "submit")
	public WebElement LoginButtom;

	public boolean isOnThisPage() {
		return loginForm.isDisplayed();
	}

	@Override
	public void tryToOpen() {
		MyPageFactory.getPage(driver, InternalPage.class).logout();

	}

	public InternalPage LoginWithValidCredentials(String username, String password) {
		// Login
		userNameField.sendKeys(username);
		passwordField.sendKeys(password);
		LoginButtom.click();
		return MyPageFactory.getPage(driver, InternalPage.class);
	}
	public LoginPage LoginWithWrongCredentials(String username, String password) {
		// Login
		userNameField.sendKeys(username);
		passwordField.sendKeys(password);
		LoginButtom.click();
		return MyPageFactory.getPage(driver, LoginPage.class);
	}

}
